#!/bin/bash

#################
#
# 安装ssh
#

cd ~;
ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa >> a.txt;
cd .ssh/;
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys;
chmod 600 authorized_keys;
#################

#################
#
# 安装 hadoop
#
#################
echo 'HADOOP_HOME=/home/hadoop/app/hadoop-2.6.0-cdh5.7.0' >> /etc/profile;
echo 'export PATH=$HADOOP_HOME/bin:$PATH' >> /etc/profile;
cd ~;
mkdir software;cd software;
groupadd hadoop;
useradd -g hadoop hadoop;
mkdir -p /home/hadoop/app/;
wget http://47.114.163.161:8087/hadoop/hadoop-2.6.0-cdh5.7.0.tar.gz;
tar -zxf hadoop-2.6.0-cdh5.7.0.tar.gz -C /home/hadoop/app/;

mkdir -p /usr/local/data/namenode;
mkdir -p /usr/local/data/datanode;
mkdir -p /usr/local/data/tmp;

#################
# 配置 hadoop-env.sh
#################
sed -i '25d' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hadoop-env.sh;
sed -i '24a export JAVA_HOME=/usr/java/jdk1.8.0_212' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hadoop-env.sh;
sed -i '25a export HADOOP_PREFIX=/home/hadoop/app/hadoop-2.6.0-cdh5.7.0' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hadoop-env.sh;

#################
# 配置 core-site.xml
#################
sed -i '19a <property>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/core-site.xml;
sed -i '20a <name>fs.defaultFS</name>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/core-site.xml;
sed -i '21a <value>hdfs://hadoop001:9000</value>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/core-site.xml;
sed -i '22a </property>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/core-site.xml;

#################
# 配置 core-site.xml
#################
sed -i '19a <property>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml;
sed -i '20a <name>dfs.replication</name>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml;
sed -i '21a <value>2</value>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml;
sed -i '22a </property>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml;
sed -i '23a <property>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml;
sed -i '24a <name>dfs.namenode.secondary.http-address</name>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml;
sed -i '25a <value>hadoop001:50090</value>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml;
sed -i '26a </property>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml;
sed -i '27a <property>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml;
sed -i '28a <name>dfs.namenode.secondary.https-address</name>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml;
sed -i '29a <value>hadoop001:50091</value>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml;
sed -i '30a </property>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml;
sed -i '31a <property>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml;
sed -i '32a <name>dfs.name.dir</name>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml;
sed -i '33a <value>/usr/local/data/namenode</value>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml;
sed -i '34a </property>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml;
sed -i '35a <property>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml;
sed -i '36a <name>dfs.data.dir</name>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml;
sed -i '37a <value>/usr/local/data/datanode</value>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml;
sed -i '38a </property>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml;
sed -i '39a <property>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml;
sed -i '40a <name>dfs.tmp.dir</name>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml;
sed -i '41a <value>/usr/local/data/tmp</value>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml;
sed -i '42a </property>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/hdfs-site.xml;

#################
# 配置 slaves
#################
sed -i 's/localhost/hadoop002/g' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/slaves;
sed -i '1a hadoop003' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/slaves;

#################
# 配置 mapred-site.xml
#################
cp /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/mapred-site.xml.template /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/mapred-site.xml;
sed -i '19a <property>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/mapred-site.xml;
sed -i '20a <name>mapreduce.framework.name</name>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/mapred-site.xml;
sed -i '21a <value>yarn</value>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/mapred-site.xml;
sed -i '22a </property>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/mapred-site.xml;

#################
# 配置 yarn-site.xml
#################
sed -i '17a <property>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/yarn-site.xml;
sed -i '18a <name>yarn.nodemanager.aux-services</name>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/yarn-site.xml;
sed -i '19a <value>mapreduce_shuffle</value>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/yarn-site.xml;
sed -i '20a </property>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/yarn-site.xml;

sed -i '21a <property>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/yarn-site.xml;
sed -i '22a <name>yarn.resourcemanager.hostname</name>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/yarn-site.xml;
sed -i '23a <value>hadoop001</value>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/yarn-site.xml;
sed -i '24a </property>' /home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/yarn-site.xml;


















